package com.guslegend.Class01_ioc.test;

import com.guslegend.Class01_ioc.HappyPlay;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author: guslegend
 * @description: 测试Factory
 * @create: 2025-04-27 11:17
 **/
public class FactoryBean {

    @Test
    public void textFactory(){
        ApplicationContext iocContainer=
                new ClassPathXmlApplicationContext("bean3.xml");

        //注意: 直接根据声明FactoryBean的id,获取的是getObject方法返回的对象
        HappyPlay happyPlay=iocContainer.getBean("happyPlay4", HappyPlay.class);
        System.out.println("happyPlay="+happyPlay);
        //如果想要获取FactoryBean对象, 直接在id前添加&符号即可!  &happyPlay4 这是一种固定的约束
        Object bean=iocContainer.getBean("&happyPlay4");
        System.out.println("bean="+bean);
    }
}
